﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace DeepEarth.Toolkit.Common.Converters
{
	public class BoolToVisibility : IValueConverter
	{
		public BoolToVisibility()
		{
		}

		#region TrueValue, FalseValue

		public Visibility TrueValue
		{
			get { return mTrueValue; }
			set
			{
				if (value == mTrueValue)
					return;
				mTrueValue = value;
				mFalseValue = Opposite(value);
			}
		}
		Visibility mTrueValue = Visibility.Visible;

		public Visibility FalseValue
		{
			get { return mFalseValue; }
			set
			{
				if (value == mFalseValue)
					return;
				mFalseValue = value;
				mTrueValue = Opposite(value);
			}
		}
		Visibility mFalseValue = Visibility.Collapsed;

		#endregion


		public static Visibility Opposite(Visibility v)
		{
			switch (v)
			{
				default:
				case Visibility.Collapsed:
					return Visibility.Visible;
				case Visibility.Visible:
					return Visibility.Collapsed;
			}
		}

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (Equals(true, value))
				return TrueValue;
			return FalseValue;
		}

		public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotSupportedException();
		}
	}
}
